home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / cppcom.zip / CRC.H < prev    next >
C/C++ Source or Header  |  1991-04-14  |  2KB  |  84 lines

  1. #ifndef __CRC_H
  2. #define __CRC_H
  3.  
  4. // Copyright ***********************************************************
  5. //
  6. //     The information in this file is copyright 1991 by David Orme.
  7. //
  8. //        Anyone may use this information for any purpose as long as he takes
  9. //        responsability for any and all libility incurred from its use
  10. //        or misuse and acknowledges its use in the user documentation.  This
  11. //        information is provided AS IS with no warrenty of any kind, either
  12. //        expressed or implied.
  13. //
  14. // End *****************************************************************
  15.  
  16.  
  17. // Contents *********************************************************
  18. //
  19. //    CRC class definition
  20. //
  21. // Description
  22. //
  23. //    Implements a CRC class using the CCITT CRC-16 polynomial using
  24. //    inline assembly to perform the calculation.  Suitable for XModem
  25. //    or CIS B+ protocol implementations.
  26. //
  27. // End **************************************************************
  28.  
  29.  
  30. // Interface Dependencies -------------------------------------------
  31.  
  32. // --None--
  33.  
  34.  
  35. // Implementation Dependencies --------------------------------------
  36.  
  37. // --None--
  38.  
  39.  
  40.  
  41. class CRC {
  42. private:
  43.     unsigned        crc_16;                                // CRC accumulator
  44. public:
  45.     // Constructor...
  46.     CRC(int initialize=0)    { crc_16=initialize; }
  47.  
  48.     // Member funcs...
  49.     void            initialize(unsigned value)            { crc_16=value; }
  50.                     operator unsigned int()             { return crc_16; }
  51.     unsigned        operator +=( unsigned int value );
  52. };
  53.  
  54. // Description -------------------------------------------------------------
  55. //
  56. //        Defines the CRC class.  The CRC is initialized upon construction,
  57. //        and a running value is kept in the local crc_16 accumulator.
  58. //
  59. // Constructor
  60. //
  61. //        CRC( int initialize )
  62. //
  63. //      Initialize to 0 for XMODEM and -1 for CIS B+ protocol.
  64. //
  65. // Public Members
  66. //
  67. //      operator unsigned int()
  68. //
  69. //        This operator defines an explicit or implict cast from a CRC object
  70. //        to an unsigned integer.  It returns the current value of the CRC
  71. //        accumulator.
  72. //
  73. //        unsigned int operator +=( unsigned int value )
  74. //
  75. //        Adds value to the current CRC accumulator and returns the result--
  76. //        the new current CRC.
  77. //
  78. // End ---------------------------------------------------------------------
  79.  
  80.  
  81.  
  82. #endif
  83.  
  84.